'use strict'

let field = require('../../../modules/lib/field');
let check = field.check;

let condition = {
    orderItems: { 
        $type: 'Array',
        cartItem: {
            id: true
        },
        remark: {
            id: true
        }
    },
    campusDistribution: {
        $optional: true,
        realName: true,
        campus: {
            id: true
        },
        dormitory: true
    },
    express: {
        $optional: true,
        realName: true,
        province: true,
        city: true,
        county: true,
        address: true
    },
    telephone: true,
    remark: true
};

function testCheckSuccessful(test) {
    let result = check({
        orderItems: [{ 
            cartItem: {
                id: '1'
            },
            remark: {
                id: '2'
            }
        }],
        campusDistribution: {
            realName: '金柳颀',
            campus: {
                id: '3'
            },
            dormitory: '宿舍'
        },
        telephone: true,
        remark: true
    }, condition);

    console.log(result);
    test.done();
}

function testCheckMissField(test) {
    let result = check({
        orderItems: [{ 
            //cartItem: {
            //    id: '1'
            //},
            remark: {
                //id: '2'
            }
        }, {
            cartItem: {
                //id: '7'
            },
            //remark: {
            //    id: '8'
            //}
        }],
        campusDistribution: {
            realName: '金柳颀',
            campus: {
                id: '3'
            },
            dormitory: '宿舍'
        },
        telephone: true,
        //remark: true
    }, condition);

    console.log(result);
    test.done();
}

function testCheckOptionalArray(test) {
    let result = check({
        campusDistribution: {
            realName: '金柳颀',
            campus: {
            },
            dormitory: '宿舍'
        },
        telephone: true,
        remark: true
    }, {
        orderItems: { 
            $optional: true,
            $type: 'Array',
            cartItem: {
                id: true
            },
            remark: {
                id: true
            }
        },
        campusDistribution: {
            $optional: true,
            realName: true,
            campus: {
                id: true
            },
            dormitory: true
        },
        express: {
            $optional: true,
            realName: true,
            province: true,
            city: true,
            county: true,
            address: true
        },
        telephone: true,
        remark: true
    });

    console.log(result);
    test.done();
}

module.exports = {
    testCheckSuccessful,
    testCheckMissField,
    testCheckOptionalArray
};
